import BaseView from "../baseview.js";


export default class DetailstudentView extends BaseView{

    constructor(el,stuid){
      super(el);
        //给stuid的属性
       this.stuid =stuid; 
       super.init();
       //挂载数据
       this.mouted();
    }

    render(){
       $("#show_content").html(
        `<div style='margin:50px auto'>
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                <input id="studentName" type="text" name="name" readOnly autocomplete="off" class="layui-input">
            </div> 
        </div>
  <div class="layui-form-item">
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-inline">
        <input type="text" id="studentAge"  readOnly autocomplete="off" class="layui-input">
        </div>
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">性别</label>
    <div class="layui-input-block">
      <input type="radio" id="M" name="sex" disabled  value="男" title="男">
      <input type="radio" id='F' name="sex" disabled  value="女" title="女">
    </div>
  </div>
  <div class="layui-form-item">
        <label class="layui-form-label">所在班级</label>
        <div class="layui-input-inline">
        <input type="text" id="className"  readOnly autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
       <img id='showPhoto' src="" alt="">
    </div>
    </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button id='backBtn' type='button' class="layui-btn" lay-submit lay-filter="formDemo">返回</button>
    </div>
  </div>
</form>
</div>
        `
       )      
    }
     addlayuiJs(){
        $("#addscript").html(
        `<script>
        var myform = null;
        layui.use('form', function(){
          myform = layui.form;
        });
        </script>`
        )} 
        //返回按钮
        handle(){
         $('#backBtn').click(()=>{
             window.location.hash='#/main/studentList';
         });
        }
        //挂载数据
        mouted(){
          $.ajax({
              type:"get",
              url:"/api/student/showstudentInfoDetail",
              data:{
                "studentid":this.stuid
              },
              dataType:"json",
              success(data){
                   console.log(data);
                   $("#studentName").val(data.name);
                   $("#studentAge").val(data.age);
                   if(data.gender==='男'){
                     //console.log("男");
                       $("#M").attr("checked","checked");
                   }else{
                   // console.log("女");
                    $("#F").attr("checked","checked");
                   }
                   $("#className").val(data.classid.name);
                   //设置显示的图片
                   $("#showPhoto").attr("src",`/api/photos/${data.photo}`)
                  //重新渲染
                   myform.render();
              }
          });
        }
    }